package com.bi.design.controller;

import com.alibaba.fastjson.JSONArray;
import com.bi.design.config.ImouTools;
import com.bi.design.entity.Monitor;
import com.bi.design.mapper.MonitorMapper;
import com.bi.design.tools.ApiResult;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/imou")
public class ImouController {

    private final ImouTools imouTools;
    private final MonitorMapper monitorMapper;

    @GetMapping("/getUrl")
    @ResponseBody
    public JSONArray getVideo() {
        return imouTools.getLiveStreamInfo();
    }

    @PostMapping("/device-snap")
    @ResponseBody
    public ApiResult<String> setDeviceSnap() {
        Monitor monitor = new Monitor();
        monitor.setMediaUrl(imouTools.setDeviceSnap());
        monitorMapper.insert(monitor);
        return ApiResult.ok();
    }

}
